package com.velvetantler.weather.view.splash

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.velvetantler.weather.MainActivity
import com.velvetantler.weather.constants.Constants
import com.velvetantler.weather.utils.PreferenceUtil
import com.velvetantler.weather.view.login.LoginActivity

/**
 * 启动页 判断有无token，决定页面走向
 */
@SuppressLint("CustomSplashScreen")
class SplashActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // 检查是否有token
        val token = PreferenceUtil.getInstance(this).getValue(Constants.TOKEN_PREF_KEY)
        if (!token.isNullOrEmpty()) {
            // 跳转至主页
            val intent = Intent(this, MainActivity::class.java)
            startActivity(intent)
            finish()
        } else {
            // 跳转至登录页面
            val intent = Intent(this, MainActivity::class.java)
            startActivity(intent)
            finish()
        }
    }
}